import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('d:\\test\\qaz.jpg')
h, w, _ = img.shape

imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
_, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

img2 = cv2.drawContours(img, contours, -1, (0, 255, 0), 3)

cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.resizeWindow('image', 800, 600)  # 定义frame的大小
cv2.imshow('image', img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
